package org.example.petitionplatformsystem.controller;

import org.example.petitionplatformsystem.Response;
import org.example.petitionplatformsystem.dao.model.LeaderReply;
import org.example.petitionplatformsystem.dto.leaderReplyDTO.LeaderPostReplyDTO;
import org.example.petitionplatformsystem.service.LeaderReplyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.List;

@RestController
@RequestMapping("/consulting")
public class leaderReplyController {
    @Autowired
    private LeaderReplyService leaderReplyService;
    @GetMapping("/getleaderReply&userId={userId}&mailBoxId={mailBoxId}")
    public Response<LeaderReply> getLeaderReply(@PathVariable Long userId ,@PathVariable Long mailBoxId){
        return Response.newSuccessResponse(leaderReplyService.getLeaderReplyByMailBoxId(mailBoxId));
    }
    @PostMapping("/postleaderReply")
    public Response<LeaderReply> postLeaderReply(@RequestBody LeaderPostReplyDTO leaderPostReplyDTO){
        LeaderReply leaderReply = new LeaderReply();
        leaderReply.setMailboxId(leaderPostReplyDTO.getMailBoxId());
        leaderReply.setReplyContent(leaderPostReplyDTO.getLeaderReply());
        leaderReply.setLeaderName(leaderPostReplyDTO.getLeaderName());
        leaderReply.setUserId(leaderPostReplyDTO.getUserId());
        LocalDateTime now = LocalDateTime.now();
        leaderReply.setReplyDate(now);
        return Response.newSuccessResponse(leaderReplyService.addLeaderReply(leaderReply));
    }
    @GetMapping("/{userid}/getleaderAllReply")
    public Response<List<LeaderReply>> getLeaderAllReply(@PathVariable Long userid){
        return Response.newSuccessResponse(leaderReplyService.getLeaderReplyByUserId(userid));
    }


}
